package cn.yuan.xiaoyu.newsmodule.fragment;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import cn.yuan.xiaoyu.R;
import cn.yuan.xiaoyu.commonmodule.fragment.BaseFragment;
import cn.yuan.xiaoyu.newsmodule.adapter.NewsHomePagerAdapter;

/**
 * Created by yukuoyuan on 2017/3/7.
 * 这是一个新闻列表的主界面
 */
public class NewsHomeFragment extends BaseFragment {
    @Bind(R.id.tl_news_home)
    TabLayout tlNewsHome;
    @Bind(R.id.vp_news_home)
    ViewPager vpNewsHome;
    //    页面集合
    private List<Fragment> fragments = new ArrayList<>();
    //    标题集合
    private List<String> list = new ArrayList<>();
    //    private String[] titles = new String[]{"推荐", "视频", "热点", "社会", "娱乐", "科技", "汽车", "体育", "财经", "军事", "国际", "时尚", "游戏", "旅游", "历史", "探索", "美食", "育儿", "养生", "故事", "美文"};
//    private String[] titlesCode = new String[]{"__all__", "video", "news_hot", "news_society", "news_entertainment", "news_tech", "news_car", "news_sports", "news_finance", "news_military", "news_world", "news_fashion", "news_game", "news_travel", "news_history", "news_discovery", "news_food", "news_baby", "news_regimen", "news_story", "news_essay"};
    private String[] titles = new String[]{"推荐", "视频", "热点"};
    private String[] titlesCode = new String[]{"__all__", "video", "news_hot"};

    @Override
    public void initdata(Bundle arguments) {
        for (int i = 0; i < 3; i++) {
            fragments.add(NewsHomeListFragment.newInstance(titlesCode[i]));
        }
        for (int i = 0; i < 3; i++) {
            list.add(titles[i]);
        }
        tlNewsHome.setTabMode(TabLayout.MODE_FIXED);
        for (int i = 0; i < 3; i++) {
            tlNewsHome.addTab(tlNewsHome.newTab().setText(list.get(i)));
        }
        NewsHomePagerAdapter myPatientPagerAdapter = new NewsHomePagerAdapter(getActivity().getSupportFragmentManager(), fragments, list);
        vpNewsHome.setAdapter(myPatientPagerAdapter);
        tlNewsHome.setupWithViewPager(vpNewsHome);
//        tlNewsHome.post(new Runnable() {
//            @Override
//            public void run() {
//                MyTabLayout.instance().setIndicator(tlNewsHome, 40, 40);
//            }
//        });
    }

    @Override
    public int getContentLayout() {
        return R.layout.fragment_newshome;
    }

    @Override
    protected void bindPresenter() {

    }

    @Override
    protected void initToolbar() {

    }

}
